<?php
declare (strict_types = 1);
namespace app\middleware;
use app\middleware\BaseMiddleware;

class CorsMiddleware  extends BaseMiddleware{
    public function handle($request, \Closure $next){
        $response = $next($request);
        /*$response->header('Access - Control - Allow - Origin', '*');
        $response->header('Access - Control - Allow - Methods', 'GET, POST, PUT, DELETE, OPTIONS');
        $response->header('Access - Control - Allow - Headers', 'Content - Type, Authorization');*/

        header('Access-Control-Allow-Origin: *');//容许全部访问地址
        header("Access-Control-Allow-Headers: token,Origin, X-Requested-With, Content-Type, Accept");//设置你要请求的头部信息
        // header("Access-Control-Allow-Headers: Content-Type, Authorization");
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');//设置你请求的方式
        header('Access-Control-Allow-Credentials:false');//设置容许cookie跨域，这里若是设置为true上面就不能容许全部的地址了，要改成指定地址

        return $response;
    }




}